<template>
	<view class="deliver">
		<!-- 全部 -->
		<view class="content-item content-item-all">
			<!-- 岗位列表 -->
			<view class="recruit" v-if="JSON.stringify(getrecList) !== '[]'">
				<view class="text">投递-岗位</view>
				<view v-for="(item1, index1) in getrecList" :key="item1.id" class="setBorder">
					<recruitList :recruitData="item1" @recruitDetail="gotorecruitDetail(item1)" :delDeliver="true" @delRecruitItem="delRecruitItem"></recruitList>
				</view>
			</view>
			<!-- 兼职列表 -->
			<view class="parttime" v-if="JSON.stringify(getparList) !== '[]'">
				<view class="text">投递-兼职</view>
				<view v-for="(item2, index2) in getparList" :key="item2.id">
					<parttimeList :parttimeData="item2" @parttimeDetail="gotoParttimeDetail(item2)" :delDeliver="true" @delParttimeItem="delParttimeItem"></parttimeList>
				</view>
			</view>
		</view>
		<view class="content-item nodata" v-if="JSON.stringify(getrecList) === '[]' && JSON.stringify(getparList) === '[]'">暂无投递~</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';

export default {
	data() {
		return {
		};
	},
	methods: {
		// 跳转去兼职详情
		gotoParttimeDetail(item) {
			uni.navigateTo({
				// url要传id参数
				url: '/subpkg/parttime/parttimeDetail?item=' + encodeURIComponent(JSON.stringify(item))
			});
		},
		// 跳转去岗位详情
		gotorecruitDetail(item) {
			uni.navigateTo({
				// url要传id参数
				url: '/subpkg/recruit/recruitDetail?item=' + encodeURIComponent(JSON.stringify(item))
			});
		},
		delRecruitItem(recruitData) {
			var recruit = this.getrecList;
			recruit = recruit.filter((list) => list.id !== recruitData.id);
			uni.setStorageSync('deliverRecruit', JSON.stringify(recruit));
			uni.reLaunch({
				url: '/subpkg/submy/myService/myDeliver'
			});
			// this.isdel=true
			// this.getrecList=false
		},
		delParttimeItem(parttimeData) {
			var parttime = this.getparList;
			parttime = parttime.filter((list) => list.id !== parttimeData.id);
			uni.setStorageSync('deliverParttime', JSON.stringify(parttime));
			uni.reLaunch({
				url: '/subpkg/submy/myService/myDeliver'
			});
		},
		getRecruit() {
			return JSON.parse(uni.getStorageSync('deliverRecruit') || '[]');
		}
	},
	computed: {
		...mapState(['token']),

		// 没有token不展示内容
		getrecList() {
				if (this.token) {
					// return this.applyRecruitList
					return JSON.parse(uni.getStorageSync('deliverRecruit') || '[]');
				} else {
					return [];
				}
		},
		// 没有token不展示内容
		getparList() {
			if (this.token) {
				return JSON.parse(uni.getStorageSync('deliverParttime') || '[]');
			} else {
				return [];
			}
		}
	},
	// 返回首页
	onNavigationBarButtonTap() {
		uni.reLaunch({
			url: '/pages/home/home'
		});
	}
};
</script>

<style lang="scss" scoped>
.deliver {
	margin-top: 22rpx;
}
.recuirLists-item {
	border-bottom: 2rpx solid #bbbbbb;
	&:last-child {
		border-bottom: 0;
	}
}
.content-item {
	padding: 20rpx 0;
}
.content-item-all {
	padding-top: 0;
	.text {
		width: 100%;
		color: white;
		margin-bottom: 20rpx;
		text-align: center;
		background-color: #2979ff;
		padding: 14rpx 0;
		font-size: 38rpx;
		font-weight: 700;
	}
	.parttime {
		.text {
			margin-bottom: 50rpx;
		}
	}
	.recruit,
	.parttime {
		box-shadow: 0 0 12rpx #ccc;
		margin: 10rpx 20rpx 40rpx;
		border-radius: 12rpx;
		padding-bottom: 30rpx;
		overflow: hidden;
	}
	.setBorder {
		border-top: 0;
		border-bottom: 2rpx solid #bbbbbb;
		&:last-child {
			border-bottom: 0;
		}
	}
}
.content-item-parttime {
	padding-top: 20rpx;
}
/* 无数据 */
.nodata {
	width: 100%;
	text-align: center;
	color: #bbbbbb;
}
</style>
